package com.qf.dao.impl;

import com.qf.dao.MyProductsDao;
import com.qf.dao.ProductsDao;
import com.qf.entity.Products;
import com.qf.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class ProductsDaoImpl implements ProductsDao {

    private QueryRunner queryRunner = new QueryRunner(JdbcUtils.ds);

    @Override
    public List<Products> selectProAll() {
        try {
            return queryRunner.query("select * from t_products",new BeanListHandler<>(Products.class));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Products selectByID(int id) {
        try {
            return queryRunner.query("select * from t_products where id = ?",new BeanHandler<>(Products.class),id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
